package ACMProble;

import java.io.BufferedInputStream;  
import java.util.Scanner;  
  
public class Pro2031 {  
      
    static void f(int n, int r) {  
        if(n != 0) {  
            f(n / r, r);  
            System.out.print((char)(n % r > 9 ? n%r-10 + 'A' : n%r + '0') );  
        }  
    }  
    public static void main(String[] args) {  
        Scanner s = new Scanner(new BufferedInputStream(System.in));  
        int n, r;  
        while(s.hasNext()) {  
            n = s.nextInt();  
            r = s.nextInt();  
            if(n > 0) {  
                f(n, r);  
                System.out.println();  
            }  
            else if(n == 0)  
                System.out.println('0');  
            else {  
                System.out.print('-');  
                f(-n, r);  
                System.out.println();  
            }  
  
        }  
        s.close();
    }  
  
}  